package com.neusoft.elmboot.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;

@RestController
@RequestMapping("/Orders")
public class OrdersController {
	private static final Logger logger = LoggerFactory.getLogger(OrdersController.class);

	@Autowired
	private OrdersService ordersService;
	
	@RequestMapping(method = RequestMethod.POST)
	public int createOrders(Orders orders) throws Exception{
		return ordersService.createOrders(orders);
	}
	
	@RequestMapping(value = "/orderId/{orderId}", method = RequestMethod.GET)
	public Orders getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception{
		return ordersService.getOrdersById(orderId);
	}
	
	@RequestMapping(value = "/userId/{userId}", method = RequestMethod.GET)
	public List<Orders> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception{
		return ordersService.listOrdersByUserId(userId);
	}

	@RequestMapping(method = RequestMethod.PUT)
	public int updateOrders(Integer orderId) throws Exception{
		logger.error(" " + orderId);
		return ordersService.updateOrders(orderId);
	}

	@RequestMapping(value = "/orderId/{orderId}", method = RequestMethod.DELETE)
	public int deleteOrders(Orders orders) throws Exception{
		return ordersService.deleteOrders(orders);
	}


}
